package com.sahyadri.web.util.tags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 * The Class InlineStatusMessageTag.
 * 
 */
public class InlineStatusMessageTag extends SimpleTagSupport {

	private static final String DEFAULT_SUCCESS_MAIN_CSS_CLASS = "status-message-success-main";
	private static final String DEFAULT_ERROR_MAIN_CSS_CLASS = "status-message-error-main";
	private static final String DEFAULT_CONTENT_CSS_CLASS = "status-message-content";
	
	private String id;
	//Set the default values for the optional tag values
	private String messageContentCssClass = DEFAULT_CONTENT_CSS_CLASS;
	private String successMainCssClass = DEFAULT_SUCCESS_MAIN_CSS_CLASS;
	private String errorMainCssClass = DEFAULT_ERROR_MAIN_CSS_CLASS;

	/* (non-Javadoc)
	 * @see javax.servlet.jsp.tagext.SimpleTagSupport#doTag()
	 */


	public void doTag() throws JspException, IOException {

		JspWriter out = getJspContext().getOut();  
	
    	StringBuffer script = new StringBuffer();

    	script.append(getStatusHtml());    	
    	
    	out.print(script);
        out.flush();
	}
	
	/**
	 * Gets the Html string for the status messages
	 * 
	 * @return the Javascript string for the status messages
	 */
	private String getStatusHtml()
	{
		String newline = System.getProperty("line.separator");
		StringBuffer script = new StringBuffer();
		script.append(newline);
		script.append("<div id=\""+getId()+"\" class=\""+getSuccessMainCssClass()+"\" style=\"display:none;\">" + newline);
		script.append("		<span id=\""+ getId()+ "Content\" class=\""+getMessageContentCssClass()+"\"></span>" + newline);
		script.append("</div>" + newline);
		return(script.toString());
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getSuccessMainCssClass() {
		return successMainCssClass;
	}


	public void setSuccessMainCssClass(String successMainCssClass) {
		this.successMainCssClass = successMainCssClass;
	}


	public String getErrorMainCssClass() {
		return errorMainCssClass;
	}


	public void setErrorMainCssClass(String errorMainCssClass) {
		this.errorMainCssClass = errorMainCssClass;
	}
	
	public String getMessageContentCssClass() {
		return messageContentCssClass;
	}


	public void setMessageContentCssClass(String messageContentCssClass) {
		this.messageContentCssClass = messageContentCssClass;
	}
	
	
}

